package com.module.base.adapter.drag;

import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.module.base.base.adapter.BaseNewViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

/**
 * Description :
 *
 * @author bsnl_yanxuwen
 * @date 2020/1/1617:39
 * 多类型 拖曳排序
 */
public abstract class DragMultiAdapter extends DragAdapter<MultiItemEntity> {

    public DragMultiAdapter(RecyclerView recyclerView) {
        super(recyclerView);
    }

    public abstract BaseNewViewHolder onCreateMultiViewHolder(ViewGroup parent, int viewType);

    @Override
    public BaseNewViewHolder onCreateNewViewHolder(ViewGroup parent, int viewType) {
        return onCreateMultiViewHolder(parent, viewType);
    }

    @Override
    public int getItemViewType(int position) {
        if (getHeaderLayoutCount() != 0 && getHeaderLayoutCount() > position) {
            return super.getItemViewType(position);
        }
        if (getData() != null && getData().size() + getHeaderLayoutCount() > position) {
            return getRealItemViewType(position - getHeaderLayoutCount());
        }
        return super.getItemViewType(position);
    }


    /**
     * 已去除头部的 ItemViewType
     */
    protected int getRealItemViewType(int position) {
        return getData().get(position).getItemType();
    }
}
